//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

namespace Microsoft.Research.ScientificWorkflow.ManagementStudioControls.RegistryManagerModule
{
    using System;
    using System.Collections.Generic;

    /// <summary>
    /// Presenter factory, abstraction for type to presenter mapping.
    /// </summary>
    public static class RegistryManagerPresenterFactory
    {
        private static Dictionary<Type, IRegistryManagerCenterPanePresenter> presenterDictionary = new Dictionary<Type, IRegistryManagerCenterPanePresenter>();

        /// <summary>
        /// Registers the presenter.
        /// </summary>
        /// <param name="modelType">Type of the model.</param>
        /// <param name="centerPanePresenter">The center pane presenter.</param>
        public static void RegisterPresenter(Type modelType, IRegistryManagerCenterPanePresenter centerPanePresenter)
        {
            if (modelType != null && centerPanePresenter != null)
            {
                RegistryManagerPresenterFactory.presenterDictionary[modelType] = centerPanePresenter;
            }
        }

        /// <summary>
        /// Fetches the center pane presenter.
        /// </summary>
        /// <param name="modelType">Type of the model.</param>
        /// <returns>The center pane presenter</returns>
        public static IRegistryManagerCenterPanePresenter FetchCenterPanePresenter(Type modelType)
        {
            IRegistryManagerCenterPanePresenter centerPanePresenter = null;
            if (RegistryManagerPresenterFactory.presenterDictionary.ContainsKey(modelType))
            {
                centerPanePresenter = RegistryManagerPresenterFactory.presenterDictionary[modelType];
            }

            return centerPanePresenter;
        }

        /// <summary>
        /// Determines whether presenter registered for the specified model type.
        /// </summary>
        /// <param name="modelType">Type of the model.</param>
        /// <returns>
        /// 	<c>true</c> if presenter registered for the specified model type; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsPresenterRegistered(Type modelType)
        {
            bool registered = false;
            if (modelType != null)
            {
                registered = RegistryManagerPresenterFactory.presenterDictionary.ContainsKey(modelType);
            }

            return registered;
        }
    }
}
